import numpy as np
import pandas as pd
import networkx as nx

edges = pd.DataFrame()
# sources：起始结点
edges['sources'] = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5]
# targets：终止结点
edges['targets'] = [2, 4, 5, 3, 1, 2, 5, 1, 5, 1, 3, 4]
# weights：点边权重
edges['weights'] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

# 创建一个图
G = nx.from_pandas_edgelist(edges, source='sources', target='targets', edge_attr='weights')

# degree 度
print("degree:", nx.degree(G))
# 连通分量
print("连通分量：", list(nx.connected_components(G)))
# 图直径（图中所有点的最短路径的最大值）
print("图直径：", nx.diameter(G))
# 度中心性
print("度中心性：", nx.degree_centrality(G))
# 特征向量中心性
print("特征向量中心性：", nx.eigenvector_centrality(G))
# betweenness
print("betweenness：", nx.betweenness_centrality(G))
# closeness
print("closeness：", nx.closeness_centrality(G))
# pagerank
print("pagerank：", nx.pagerank(G))
# HITS
print("HITS-hubs：", nx.hits(G)[0])
print("HITS-authorities：", nx.hits(G)[1])
